package org.mtdownload.infoview;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;

import org.mtdownload.download.DownloadManager;
import org.mtdownload.download.DownloadTask;
import org.mtdownload.download.DownloadTaskPropertiesChanged;

public class MTDownloadInfoView extends JPanel {

	private static final long serialVersionUID = 3835158376022750004L;
	private DownloadTask curentlySelectedTask=null;
	private InfoViewTableModel model=new InfoViewTableModel();

	public MTDownloadInfoView() {
		init();
	}
	
	private void init(){
		DownloadManager.addDownloadTaskPropertiesChangedListener(new DownloadTaskPropertiesChanged(){
			public void propertiesChanged(DownloadTask task) {
				if(task.equals(curentlySelectedTask)){
					model.updateData(curentlySelectedTask);
				}
			}
		});
		setLayout(new BorderLayout());
		JTable table=new JTable(model);
		JScrollPane scroll=new JScrollPane(table);
		TableColumnModel colModel=table.getColumnModel();
		colModel.getColumn(0).setMaxWidth(150);
		colModel.getColumn(0).setPreferredWidth(150);
		add(scroll,BorderLayout.CENTER);
	}
	
	

	/**
	 * @return Returns the curentlySelectedTask.
	 */
	public DownloadTask getCurentlySelectedTask() {
		return curentlySelectedTask;
	}
	

	/**
	 * @param curentlySelectedTask The curentlySelectedTask to set.
	 */
	public void setCurentlySelectedTask(DownloadTask curentlySelectedTask) {
		this.curentlySelectedTask = curentlySelectedTask;
		model.updateData(curentlySelectedTask);
	}
	

}
